using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class ProductDetailChildWindowModel : ModelBase
    {
        public ProductDetailChildWindowModel()
        {
            client.GetSingleProductCompleted += DoGetSingleProductCompleted;
            client.InsertProductCompleted += DoInsertProductCompleted;
            client.UpdateProductCompleted += DoUpdateProductCompleted;
        }

        #region UpdateProduct

        public event EventHandler<FeedbackCompletedEventArgs> UpdateProductCompleted;

        public int UpdateProductAsync(Product data)
        {
            client.UpdateProductAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoUpdateProductCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UpdateProductCompleted != null)
            {
                UpdateProductCompleted(sender, e);
            }
        }

        #endregion

        #region InsertProduct

        public event EventHandler<SingleFeedbackCompletedEventArgs<int>> InsertProductCompleted;

        public int InsertProductAsync(Product data)
        {
            client.InsertProductAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoInsertProductCompleted(object sender, SingleFeedbackCompletedEventArgs<int> e)
        {
            if (InsertProductCompleted != null)
            {
                InsertProductCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleProduct

        public event EventHandler<SingleFeedbackCompletedEventArgs<Product>> GetSingleProductCompleted;

        public int GetSingleProductAsync(int objID)
        {
            client.GetSingleProductAsync(objID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleProductCompleted(object sender, SingleFeedbackCompletedEventArgs<Product> e)
        {
            if (GetSingleProductCompleted != null)
            {
                GetSingleProductCompleted(sender, e);
            }
        }

        #endregion

    }
}